<?php
$base = $_SERVER['SERVER_NAME'];
?>
<head>
    <link href="http://<?= $base ?>/bootstrap/facefiles/facebox.css" media="screen" rel="stylesheet" type="text/css" />
    <script src="http://<?= $base ?>/bootstrap/facefiles/facebox.js" type="text/javascript"></script>
    <script type="text/javascript">
        jQuery(document).ready(function($) {
            $('a[rel*=facebox]').facebox()
        });
    </script>
    <script type="text/javascript" src="http://<?= $base ?>/bootstrap/stepcarousel/stepcarousel.js"></script>

    <style type="text/css">

        .stepcarousel{
            position: relative; /*leave this value alone*/            
            overflow: scroll; /*leave this value alone*/
            width: 300px; /*Width of Carousel Viewer itself*/
            height: 300px; /*Height should enough to fit largest content's height*/
        }

        .stepcarousel .belt{
            position: absolute; /*leave this value alone*/
            left: 0;
            top: 0;
        }

        .stepcarousel .panel{
            float: left; /*leave this value alone*/
            overflow: hidden; /*clip content that go outside dimensions of holding panel DIV*/
            /**/            margin: 5px; /*margin around each panel*/
            margin-left: 15px;
            width: 320px; /*Width of each panel holding each content. If removed, widths should be individually defined on each content DIV then. */
        }

    </style>



    <script type="text/javascript">

        stepcarousel.setup({
            galleryid: 'mygallery', //id of carousel DIV
            beltclass: 'belt', //class of inner "belt" DIV containing all the panel DIVs
            panelclass: 'panel', //class of panel DIVs each holding content
            autostep: {enable: true, moveby: 1, pause: 3000},
            panelbehavior: {speed: 500, wraparound: false, wrapbehavior: 'slide', persist: true},
            defaultbuttons: {enable: true, moveby: 1, leftnav: ['http://<?= $base ?>/bootstrap/stepcarousel/leftnav.gif', -5, 80], rightnav: ['http://<?= $base ?>/bootstrap/stepcarousel/rightnav.gif', -20, 80]},
            statusvars: ['statusA', 'statusB', 'statusC'], //register 3 variables that contain current panel (start), current panel (last), and total panels
            contenttype: ['inline'] //content setting ['inline'] or ['ajax', 'path_to_external_file']
        })

    </script>
</head>
<div class="row-fluid">        
    <div class="span12">
        <table class="table well">
            <tbody>
                <?php
                foreach ($this->details as $detail) :
                    $db = new Ads_Model_Rentdetails();
                    $zipDb = new Ads_Model_Zipcode();
                    $rentDetailsArray = $db->getDetailsJson($detail->details);
                    $photoArray = $db->getPhotoArrayFromJson($rentDetailsArray);
                    ?>                
                    <tr>
                        <td>
                            <div class="span3">
                                <div id="mygallery" class="stepcarousel">
                                    <div class="belt">
                                        <?php for ($index = 0; $index < count($photoArray); $index++) { ?>
                                            <div class="panel">
                                                <a href="/uploads/<?= $photoArray[$index]; ?>" rel="facebox"><img src="/uploads/<?= $photoArray[$index]; ?>" height="270" width="270" /></a>
                                            </div>
                                        <?php }
                                        ?>


                                    </div>
                                </div>
                                <div class="span10"><center>
                                        <a class="btn btn-success btn-small" href="<?= $this->url(array('id' => $detail->id), 'contact-owner'); ?>"><i class="icon-user icon-white"></i> Contact Owner</a>
                                        <a href="#myModal" role="button" class="btn btn-danger btn-small" data-toggle="modal"><i class="icon-white icon-map-marker"></i> View Map</a></center>
                                </div>
                                <!--<img src="/uploads/<?= $photoArray[0]; ?>" width="250" height="250" />-->
                            </div>
                            <!--<div class="span1"></div>-->
                            <div class="span8 well offset1">
                                <div>
                                    <title><?php
                                        $title = $rentDetailsArray->adTitle;
                                        echo $title;
                                        ?></title>
                                    <h4>Title: <?= $title; ?></h4>
                                </div>
                                <div><b>Description:</b> 
                                    <?php echo $rentDetailsArray->adDesc; ?>
                                </div>
                                <div class="span6">
                                    <i class="search-def search-rent" title="rent/month"></i> Rent/month:  <b><?= $rentDetailsArray->rent; ?> DKK/month</b><br>
                                    <i class="search-def search-period" title="Rental Period"></i> Rental Period: <b><?= $db->getRentalPeriod($rentDetailsArray); ?></b><br>
                                    <i class="search-def search-apartment" title="Property Type"></i> Property Type: <b><?= $db->getPropertyType($rentDetailsArray); ?></b>
                                </div>
                                <div class="span6">
                                    <i class="search-def search-city" title="city"></i> City: <b> <?php
                                        $zipData = $zipDb->getByPrimaryKey($rentDetailsArray->zipcode);
                                        $cityId = $zipData[0]['city_id'];
                                        $cityDb = new Ads_Model_City();
                                        $cityData = $cityDb->getCityById($cityId);
                                        echo $cityName = $cityData[0]['name'];
                                        $stateId = $cityData[0]['state_id'];
//                                        $cityDb = new Ads_Model_City();
//                                        $cityData = $cityDb->getCityById($rentDetailsArray->city);
//                                        $cityName = $cityData[0]['name'];
//                                        echo $cityName;
                                        ?></b><br>
                                    <i class="search-def search-area" title="Area of property"></i> Area: <b><?= $rentDetailsArray->area; ?> m<sup>2</sup></b><br>
                                    <i class="search-def search-bedrooms" title="Total Rooms"></i> Rooms:  <b><?= $rentDetailsArray->rooms; ?> room(s)</b>
                                </div>
                                <div>
                                    House No.: <b><?= $rentDetailsArray->houseno; ?></b><br>
                                    Street Name:<b> <?php echo $streetName = $rentDetailsArray->streetName ?></b><br>
                                    Zip code: <b> <?php
//                                        $zipData = $zipDb->getByPrimaryKey($rentDetailsArray->zipcode);
                                        $zipCode = $zipData[0]['codes'];
                                        echo $zipCode;
                                        ?></b><br>
                                    State: <b><?php
                                        $stateDb = new Ads_Model_State();
                                        $stateData = $stateDb->getStateById($stateId);
                                        $stateName = $stateData[0]['name'];
                                        echo $stateName;
                                        ?></b><br>
                                    Furnished: <b><?= $db->getFurnishType($rentDetailsArray) ?></b><br>
                                    Deposite: <b><?= $rentDetailsArray->depositeValue ?> DKK  (<?= $db->getDepositeType($rentDetailsArray) ?>)</b><br>
                                    Pre-paid Rent: <b><?= $rentDetailsArray->prerentValue ?> DKK (<?= $db->getPrerentType($rentDetailsArray) ?>)</b>
                                </div>
                            </div>                            
                        </td>
                    </tr>
                    <?php
                endforeach;
                ?>
            </tbody>
        </table>                
    </div>
</div>


<div id="myModal" class="modal hide fade" style="width: 800px; margin-left: -350px;" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 id="myModalLabel"><?= $title ?></h3>
    </div>
    <div class="modal-body">
        <?php
        $iframe_width = '770px';
        $iframe_height = '350px';
        $address = urlencode("$zipCode, $cityName,$streetName,  Denmark");
        //echo '<br>'.$address = urlencode("8000, Aarhus, Denmark");
        $key = "AIzaSyDu_mId5r1Nk1ZQDxpkoyAd1Q4qXseigEQ";
        $url = "http://maps.google.com/maps/geo?q=" . $address . "&output=json&key=" . $key;
        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

        $data = curl_exec($ch);
        curl_close($ch);

        $geo_json = json_decode($data, true);
        echo $geo_json['Status']['code'];
//        if ($geo_json['Status']['code'] == '610') {
        ?>

        <iframe width="<?php echo $iframe_width; ?>" height="<?php echo $iframe_height; ?>" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="

                http://maps.google.com/maps?f=q&q=<?=$address?>&source=s_q&hl=en&aq=0&ie=UTF8&hnear=<?php echo $address; ?>&t=m&z=18&output=embed"></iframe>

        <?php
//        } else {
//            echo "<p>No Address Available or Error in connection with Google Map.</p>";
//        }
        ?>
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>

    </div>
</div>